package com.netflexitysolutions.amazonws.ec2.internal.operations;

import org.apache.commons.codec.binary.Base64;

import com.amazonaws.ec2.doc._2009_04_04.GetConsoleOutputResponseType;
import com.amazonaws.ec2.doc._2009_04_04.GetConsoleOutputType;
import com.netflexitysolutions.amazonws.ec2.ConsoleOutput;
import com.netflexitysolutions.amazonws.ec2.EC2;
import com.netflexitysolutions.amazonws.ec2.internal.ModelUtil;

public class GetConsoleOutputOperation extends SingleObjectOperationExecutor<GetConsoleOutputType, ConsoleOutput> {

	public GetConsoleOutputOperation(EC2 ec2, String instaceId) {
		super(ec2, instaceId);
	}

	@Override
	protected ConsoleOutput call(GetConsoleOutputType request) {
		request.setInstanceId(objectId);
		GetConsoleOutputResponseType response = new GetConsoleOutputResponseType();
		return new ConsoleOutput(response.getInstanceId(), ModelUtil.toDomainType(response.getTimestamp()),
				new String(Base64.decodeBase64(response.getOutput().getBytes())));
	}

}
